<%--
  Created by IntelliJ IDEA.
  User: 林淮
  Date: 2024/12/4
  Time: 下午1:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<%--<script>--%>
<%--    function test(a, b, c, d, e) {--%>
<%--        console.log(a, b, c, d, e);--%>
<%--    }--%>

<%--    test();--%>
<%--    test("a", "b");--%>
<%--    test("a", "b", "c");--%>
<%--    test("a", "b", "c", "d");--%>
<%--    test("a", "b", "c", "d", "e", "f", "g");--%>
<%--</script>--%>
<script type="text/javascript">
    let xhr = new XMLHttpRequest();//创建异步引擎对象

    function toSend() {
        xhr.open("get", "myAjax?name=亚托克斯");//打开请求
        xhr.send(null);
        xhr.onreadystatechange = function () {//设置回调函数
            if (xhr.readyState === 4 && xhr.status === 200) {
                console.log("请求成功");
                let respText = xhr.responseText;
                console.log("响应的数据为:" + respText)
                document.getElementById("p1").innerHTML = respText;
            }
        }
    }

    function toSendPost() {
        console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
        xhr.open("post", "myAjax");
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
        xhr.send("name=卡莎&age=21");
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status === 200) {
                console.log("请求成功");
                let respText = xhr.responseText;
                console.log("响应的数据为:" + respText)
                document.getElementById("p1").innerHTML = respText;
            }
        }
    }
</script>
<body>
<button onclick="toSend()">测试一下</button>
<button onclick="toSendPost()">测试一下</button>
<script>
    document.write(Math.random());
</script>
<p id="p1">
    今天开始天气更冷了~~~~~~~~~~~~~~~~~
</p>
</body>
</html>
